package com.example.administrator.uis.view

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.R.attr.radius
import android.graphics.*
import android.support.annotation.ColorLong
import android.util.Log


/**
 * Created by Administrator on 2017/11/10 0010.
 */
class PracticeDrawArcView : View {
    private var radio = 220f

    private var xPianyi = 0f
    private var yPianyi = 0f
    public val biLis = floatArrayOf(24f, 15f, 5f, 10f, 2f, 18f, 26f)
    private var dangqiandushu = 0f
    var paint = Paint()
    var path = Path()

    constructor(context: Context?) : super(context) {
    }

    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
    }

    constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) {

    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)

//        var rect = RectF(70f, 20f, 150f, 100f)
//        var rectyou = RectF(70f, 23f, 150f, 103f)
//        var rect2 = RectF(68f, 18f, 148f, 98f)
        canvas?.translate(canvas.width * 0.5f, canvas.height * 0.5f)
        var rect = RectF(-radio, -radio, radio, radio)
        paint.color = Color.BLACK
        for (bili in biLis) {
            paint.style = Paint.Style.FILL
            var dushu: Float = bili / 100 * 360
            var zongyiban = dangqiandushu + dushu / 2
            var lineStartX = radio * Math.cos(zongyiban / 180 * Math.PI).toFloat()
            var lineStartY = radio * Math.sin(zongyiban / 180 * Math.PI).toFloat()
            var lineEndX = (radio + 50) * Math.cos(zongyiban / 180 * Math.PI).toFloat()
            var lineEndY = (radio + 50) * Math.sin(zongyiban / 180 * Math.PI).toFloat()
//            Log.d("LineStartx","$lineStartX")
            if (isMax(bili)) {
                canvas?.translate(lineStartX * 0.1f, lineStartY * 0.1f)
                canvas?.save()
            }
            canvas?.drawArc(rect, dangqiandushu, dushu - 2f, true, paint)

//            canvas?.drawLine(lineStartX, lineStartY, lineEndX, lineEndY, paint)
            paint.color = Color.RED
            /* when (zongyiban) {
                 in 0..90, in 270..360 -> {
                     canvas?.drawLine( lineEndX, lineEndY,lineEndX+150, lineEndY, paint)
                     paint.color=Color.GRAY
                     paint.textSize=20f
                     canvas?.drawText("我日",lineEndX+150, lineEndY,paint)
                 }
                 in 90..270 -> {
                     canvas?.drawLine( lineEndX, lineEndY,lineEndX-150, lineEndY, paint)
                     paint.textSize=25f
                     canvas?.drawText("去你大爷的",lineEndX-150-(paint.measureText("去你大爷的")), lineEndY,paint)
                 }
             }*/

            paint.style = Paint.Style.STROKE//path 必需品
            path.reset()
            path.moveTo(lineStartX, lineStartY)
            path.lineTo(lineEndX, lineEndY)
            when (zongyiban) {
                in 0..90, in 270..360 -> {
                    path.rLineTo(150f, 0f)
                    canvas?.drawPath(path, paint)
                    canvas?.drawText("我日", lineEndX + 150, lineEndY, paint)
                }
                in 90..270 -> {
                    path.rLineTo(-150f, 0f)
                    canvas?.drawPath(path, paint)
                    paint.textSize = 25f
                    canvas?.drawText("去你大爷的", lineEndX - 150 - (paint.measureText("去你大爷的")), lineEndY, paint)
                }
            }



            dangqiandushu += dushu
        }
//        canvas?.drawOval(rect, paint)
//        canvas?.drawArc(rect, 0f, 30f, true, paint)
//        paint.color = Color.RED
//        canvas?.drawArc(rectyou, 30f, 60f, true, paint)
//        paint.color = Color.BLUE
//        canvas?.drawArc(rect2, 90f, 170f, true, paint)
//        canvas?.drawArc(rect2, 260f, 40f, true, paint)

    }

    private fun isMax(float: Float): Boolean {
        if (float == biLis.max()) {
            return true
        }
        return false
    }


}